<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Person_manag extends CI_Controller {

    /**
     *   网站后台
     *   王超伟
     * 	 2012.09.25
     * 	 art2006art#gmail.com
     */
    public function __construct() {
        parent::__construct();
        $this->load->helper('url');
        $this->load->helper('file');
        $this->load->helper('form');
        $this->load->helper('func');
        $this->load->database();
        $this->load->model('person_process');
        $this->load->library('file_upload'); //引入类库
    }

    public function index() {

        $person_list_array = $this->person_process->person_list();
        $data["person_list_array"] = $person_list_array;
        $this->load->view('admin/header_view');
        $this->load->view('admin/team_view', $data);
        $this->load->view('admin/footer_view');
    }

    public function del_person() {
        $id = get_segment_fuc(4);
        if (isset($id)) {

            $sqldel = "delete from person where id=\"{$id}\"";
            $this->db->query($sqldel);
        }
        redirect("admin/person_manag");
    }

    public function add_person() {
        $post_array = $_POST;
        $config['upload_path'] = './uploads/teamphoto';
        $data = $this->file_upload->upLoadfile($config, "photo");

        if (isset($data)) {
            $siteurl = site_url(); //$siteurl .
            $config["source_image"] = $data["full_path"];
            $config["new_image"] = './uploads/teamphoto/thum';
            $this->file_upload->process_img($config);
            $post_array["full_path"] = "{$data["file_name"]}";
        } else {
            $post_array["full_path"] = "";
        }

        $this->person_process->add_person($post_array);

        redirect("admin/person_manag");
    }

    //编辑团队成员
    public function edit_person() {
        if (isset($_POST["edit_submit"]) && is_numeric($_POST["id"])) {
            $this->person_process->update_person($_POST["id"]);
            redirect("admin/person_manag");
        }
        $id = get_segment_fuc(4);
        if (isset($id)) {
            $sqldel = "select * from person where id=\"{$id}\"";
            $p = $this->db->query($sqldel);
            $data['row'] = $p->row_array();
        }
        $data["edit_type"] = 'person';
        $this->load->view('admin/edit_view', $data);
    }

}

/* End of file admin.php */
/* Location: ./application/controllers/admin.php */